package com.education.business.service.system;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.education.business.mapper.system.ExamRoomMapper;
import com.education.business.service.BaseService;
import com.education.common.model.PageInfo;
import com.education.common.utils.FileUtil;
import com.education.model.dto.ExamRoomDto;
import com.education.model.entity.ExamRoom;

import com.education.model.request.PageParam;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExamRoomService extends BaseService<ExamRoomMapper, ExamRoom> {
//
//    public Page<ExamRoom> getExamRoomList(PageParam pageParam, ExamRoom examRoom){
//        Page<ExamRoom> page = new Page<>(pageParam.getPageNumber(), pageParam.getPageSize());
////        LambdaQueryWrapper<ExamRoom> queryWrapper = Wrappers.<ExamRoom>lambdaQuery().like(ExamRoom::getName,examRoom.getName());
//        Page<ExamRoom> examRoomPage =baseMapper.selectAllRoom(page,examRoom);
//
//        return baseMapper.selectAllRoom(page,examRoom);
//    }
    public PageInfo<ExamRoomDto> getExamRoomList(PageParam pageParam, ExamRoom examRoom) {
        Page<ExamRoomDto> page = new Page(pageParam.getPageNumber(), pageParam.getPageSize());
        LambdaQueryWrapper<ExamRoom> queryWrapper = Wrappers.<ExamRoom>lambdaQuery().like(ExamRoom::getName,examRoom.getName());
        return selectPage(baseMapper.getExamRoomList(page,examRoom));
    }
    //    获取未安排的考场
    public PageInfo<ExamRoomDto> selectAllNoArrangeRoom(PageParam pageParam, ExamRoom examRoom) {
        Page<ExamRoomDto> page = new Page(pageParam.getPageNumber(), pageParam.getPageSize());

        return selectPage(baseMapper.selectAllNoArrangeRoom(page,examRoom));
    }

    /**
     * 根据考试任务查询
     * 读取并写入json文件
     * @param id
     * @return
     */
    public ExamRoom ExamRoomByTaskId(int id){
        ExamRoom examRoom = baseMapper.selectById(id);
        FileUtil.WriteFile("examRoom"+".json",FileUtil.tojson(examRoom));
        return baseMapper.selectById(id);
    }
}
